package com.wish.g1.business.controller;

import com.bw.activity7.activiti.pojo.ActivitiVo;
import com.bw.activity7.activiti.pojo.UserTask;
import com.bw.activity7.activiti.service.ActivitiService;
import com.wish.g1.common.core.web.domain.AjaxResult;
import com.wish.g1.common.security.annotation.RequiresPermissions;
import com.wish.g1.common.security.utils.SecurityUtils;
import org.activiti.engine.runtime.ProcessInstance;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RequestMapping("/act")
@RestController
public class ActController {

    @Autowired
    private ActivitiService activitiService;

    @GetMapping("/createDeployment")
    public void createDeployment(){
        // 流程部署
        activitiService.createDeployment("商户审核流程", "shixun1", "bpmn/diagram_1.bpmn");
        System.err.println("@@@@@@@@@@@@@@@@@@发布");
    }

    // 启动
    @GetMapping("/askForBiz")
    public void askForBiz(){
        ActivitiVo vo = new ActivitiVo();
        String username = SecurityUtils.getUsername();
        vo.setUsername("admin");
        vo.setDeploymentKey("shixun1");
        vo.setBusinessKey("");
        vo.setVariables(new ArrayList<>());
        ProcessInstance processInstance = activitiService.askForBiz(vo);

        System.err.println("流程定义id：" + processInstance.getProcessDefinitionId());
        System.err.println("流程实例id：" + processInstance.getId());
        System.out.println("流程启动时间"+processInstance.getStartTime());
    }

    // 代办
    // @RequiresPermissions("business:act:queryUserTaskByUserName")
    @GetMapping("/queryUserTaskByUserName")
    public AjaxResult queryUserTaskByUserName(){
        ActivitiVo vo = new ActivitiVo();
        String username = SecurityUtils.getUsername();
        vo.setUsername("admin");
        List<UserTask> userTasks = activitiService.queryUserTaskByUserName(vo);
        return AjaxResult.success("",userTasks);
    }

    // 审核
    // @RequiresPermissions("business:act:completeUserTaskById")
    @GetMapping("/completeUserTaskById")
    public void completeUserTaskById(ActivitiVo vo){
        String username = SecurityUtils.getUsername();
        vo.setUsername("admin");
        activitiService.completeUserTaskById(vo);
    }

}
